package com.drdj.exam;

import java.util.ArrayList;
import java.util.Stack;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;

public class TestActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test_activity);
		
		Stack<String> st = new MyStack();
		st.add("a");
		st.add("b");
		st.add("c");
		st.add("b");
		
		
		String aa = "";
		
		while(!st.isEmpty()){
			aa += st.pop() + " ";
		}
		
		
		ArrayList<String> al = new MyArrayList();
		al.add("a");
		al.add("b");
		al.add("c");
		al.add("b");
		
		String bb = "";
		for(String s : al){
			bb += s + " ";
		}
		
		TextView tv1 = (TextView) findViewById(R.id.tvTest1);
		tv1.setText(Html.fromHtml("<font color=\"red\"> Hello </font>" + aa + "/" + bb));
	}

	// Stack that removes when the adding object is already exist.
	class MyStack extends Stack{
		@Override
		public synchronized boolean add(Object object) {
			if(contains(object)){
				remove(object);
			}
			return super.add(object);
		}
		
	}
	
	class MyArrayList extends ArrayList{
		@Override
		public boolean add(Object object) {
			if(contains(object)){
				remove(object);
			}
			return super.add(object);
		}
	}
}

